package com.hanamaki.basic.array;

import java.util.Arrays;

public class Array04 {

    public static void main(String[] args) {

        int[] a = {67, 2, 45, 432, 23, 6, 7};
        System.out.println(Arrays.toString(a));
        Arrays.sort(a);
//        System.out.println(Arrays.toString(reverser(a)));
//
//        System.out.println(max(a));
//
//        int[] b = {};
//        System.out.println(Arrays.toString(b));
//
//        printArray(a);
//
//        printArray(sort(a));

        String s = printArrays(a);
        System.out.println(s);
    }

    public static String printArrays(int a[]) {
        StringBuilder builder = new StringBuilder();
        if (a.length == 0) {
            builder.append("[]");
        } else {
            builder.append("[");
        }
        for (int i = 0; i < a.length; i++) {
            if (i < a.length - 1) {
                builder.append(a[i] + ", ");
            } else {
                builder.append(a[i] + "]");
            }
        }

        return builder.toString();

    }


//    传入 数组 ，以反转的的形式  打印数组
//    {1,2,3,4,5,6,7}
    // 反转

    //    数组 作为参数
//    数组 作为返回值
    public static int[] reverser(int[] a) {

        int[] temp = new int[a.length];
        for (int i = 0, j = temp.length - 1; i < a.length; i++, j--) {
            temp[j] = a[i];
        }
        return temp;
    }

    //    数组中元素 怎么比较大小
    public static int max(int[] a) {
        int max = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] > max) {
                max = a[i];
            }
        }
        return max;
    }

//    打印数组 方法
    public static void printArray(int[] a) {
        if (a.length < 0) {
            System.out.println("[]");
        }
        System.out.print("[");
        for (int i = 0; i < a.length; i++) {
            if (i < a.length - 1) {
                System.out.print(a[i] + ", ");
            } else {
                System.out.println(a[i] + "]");
            }
        }
    }

    //    数组 排序
    public static int[] sort(int[] a) {
        int temp = 0;

        for (int i = 0; i < a.length - 1; i++) {
            if (a[i + 1] > a[i]) {
                temp = a[i + 1];
                a[i + 1] = a[i];
                a[i] = temp;
            }
        }
        return a;
    }
}
